<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例2</title>
</head>

<body style="text-align: center;">
    请按下键盘
    <p></p>
</body>

</html>
<script>
    window.onload = function() {
        var oP = document.getElementsByTagName("p")[0];
        document.onkeydown = function(msg) {
            oP.innerHTML = msg.keyCode;
            return false
        }
    }
</script>